import {Component, OnInit, EventEmitter, Input, Output, OnChanges} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';

@Component({
    selector: 'kylin-set-line-style',
    templateUrl: './set-line-style.component.html',
    styleUrls: ['./set-line-style.component.css']
})
export class SetLineStyleComponent implements OnInit, OnChanges {
    @Input() showSetLineComponent;
    @Output() setLineStyleFun = new EventEmitter<any>();
    @Output() hideComponent = new EventEmitter<any>();
    // @Input() style;
    @Input() selectcolor;
    lineStyleForm: FormGroup;
    color = '#ffcc33';

    constructor(private fb: FormBuilder) {
    }

    ngOnChanges() {
        if (this.selectcolor === '#ffcc33' || this.selectcolor === '') {
            this.color = '#ffcc33'
        } else {
            this.color = this.selectcolor
        }
    }

    ngOnInit() {
        this.getStyleData()
    }

    getStyleData() {
        this.lineStyleForm = this.fb.group({
            lintColor: ['', [Validators.required]],
        })
    }

    // 取消
    handleAttrForm() {
        this.showSetLineComponent = false;
        this.hideComponent.emit(false);
    }

    // 确定
    submitAttrForm() {
        this.showSetLineComponent = false;
        this.setLineStyleFun.emit(this.lineStyleForm.value);
    }

}
